package com.firewolf.vue.controller;

import com.firewolf.vue.mapper.RoleMapper;
import com.firewolf.vue.params.RoleParam;
import com.firewolf.vue.pojo.Role;
import com.firewolf.vue.service.RoleService;
import com.firewolf.vue.vo.PageVo;
import com.firewolf.vue.vo.ResponseVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.management.relation.RoleInfo;
import java.util.List;

/**
 * 作者：刘兴
 * 时间:19/3/1
 **/
@RestController
@RequestMapping("/role")
@Slf4j
public class RoleController {

    @Autowired
    private RoleService roleService;

    @GetMapping("/all")
    public List<Role> getAllRoles() {
        return roleService.getAllRoles();
    }

    @GetMapping("/list")
    public PageVo<Role> findList(RoleParam param) {
        return roleService.findList(param);
    }


    @GetMapping("/menuids/{roleId}")
    public List<Long> menuids(@PathVariable("roleId") Long roleId) {
        return roleService.findMenuIds(roleId);
    }


    @PostMapping("/updaterolemenus")
    public ResponseVO updaterolemenus(Long roleid, String menuids) {

        try {
            roleService.updaterolemenus(roleid, menuids);
        } catch (Exception e) {

            log.error("授权失败", e);
            return ResponseVO.error("授权失败");
        }
        return ResponseVO.ok("授权成功");
    }
}
